package main

import (
	"flag"
	"fmt"
	"gogogo-testing-ground/utils"
	"time"
)

func main() {

	var host string
	var port int64
	var username string
	var password string
	var dir string
	var target string

	flag.StringVar(&host, "host", "", "FTPIP地址")
	flag.Int64Var(&port, "port", 21, "FTP端口")
	flag.StringVar(&username, "username", "", "FTP用户名")
	flag.StringVar(&password, "password", "", "FTP密码")
	flag.StringVar(&dir, "dir", "/", "远程FTP文件夹路径")
	flag.StringVar(&target, "target", "/", "下载目标文件夹路径")
	flag.Parse()

	cliConf := new(utils.FtpClientConfig)
	cliConf.CreateConn(host, port, username, password)
	defer cliConf.Conn.Quit()

	FtpPath := dir
	LocalPath := target

	//下载文件夹
	time1 := time.Now() // 当前时间点
	err := cliConf.DownloadDir(FtpPath, LocalPath)
	time2 := time.Now() // 当前时间点
	subTime := time2.Sub(time1).Seconds()
	fmt.Println("下载文件时间差：", subTime)
	if err != nil {
		fmt.Printf("连接发生错误:%s\n", err.Error())
	} else {
		fmt.Println("下载成功")
	}

}
